package bavaria.hightech.testit.pruefungen.ss09;


import static org.junit.Assert.*;

import java.util.Iterator;
import java.util.LinkedList;

import org.junit.Before;
import org.junit.Test;

public class CircularListImplTest {
	
	private CircularListImpl<Integer> cl;
	private CircularListImpl<String> cl2;
	private CircularListImpl<Integer> cl3;

	@Before
	public void setUp() throws Exception {
		this.cl = new CircularListImpl<Integer>();
		this.cl3 = new CircularListImpl<Integer>();
		for (int i = 1; i <= 10; i++) {
			this.cl.add(i);
			this.cl3.add(i);
		}
		
		this.cl2 = new CircularListImpl<String>();
		for (int i = 1; i <= 10; i++) {
			this.cl2.add("String" +i);
		}
	}
	
	@Test
	public void testIterator(){
		Iterator itr = cl.iterator();
		int counter = 0;
		while(itr.hasNext() && counter < 50){
			System.out.println(itr.next());
			counter++;
		}
	}
	
	@Test
	public void testToString(){
		System.out.println(cl.toString());
	}
	
	@Test
	public void testEquals(){
		assertTrue(cl.equals(cl3));
		assertFalse(cl.equals(cl2));
	}
	
	@Test
	public void testDynamicListConstructor(){
		try {
			CircularListImpl<Integer> dynCl = new CircularListImpl<Integer>(LinkedList.class);
			dynCl.add(1);
			dynCl.add(2);
			dynCl.add(3);
			System.out.println(dynCl.asList());
			System.out.println("Klassename der verwendeteten Liste: "+dynCl.getList().getClass());
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
